package com.forsir.android.mhfinance.storeObjects;

import java.util.ArrayList;
import java.util.List;

import android.database.Cursor;

import com.forsir.android.mhfinance.helper.DbAdapter;

public class RepeatingList {
	private static List<Repeating> mRepeatings = new ArrayList<Repeating>();

	public static void loadAll(DbAdapter dbHelper) {
		final Cursor cursor = dbHelper.fetchAllEntries(new Repeating(), DbAdapter.ID);
		mRepeatings = new ArrayList<Repeating>();

		if (!cursor.moveToFirst()) {
			cursor.close();
			return;
		}

		do {
			mRepeatings.add(new Repeating(cursor));
		} while (cursor.moveToNext());
		cursor.close();
	}

	public static boolean isEmpty() {
		return mRepeatings.size() == 0;
	}

	public static Repeating getRepeating(int position) {
		if (position < mRepeatings.size()) {
			return mRepeatings.get(position);
		}
		return new Repeating();
	}

	public static Repeating getRepeatingById(long repeatingId) {
		final int count = mRepeatings.size();
		for (int i = 0; i < count; i++) {
			if (mRepeatings.get(i).getId() == repeatingId) {
				return mRepeatings.get(i);
			}
		}
		return new Repeating();
	}
}
